package com.asset.utils;

import java.util.List;

/**
 * 分页
 *
 */
public class Page<T> {

    /**
     * currentPage 当前页
     */
    private int currentPage = 1;
    /**
     * pageSize 每页大小
     */
    private int pageSize = 5;
    /**
     *
     * pageTotal 总页数
     */

    private int  first ;
    private int pageTotal;
    /**
     * recordTotal 总条数
     */
    private int recordTotal = 0;

    // 获取当前页的第一条记录的索引
    public int getFirst() {
        // 计算当前页的第一条记录的索引
        return pageSize * (currentPage - 1) ;
    }

    public void setFirst(int first) {
        this.first = first;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    /**
     * content 每页的内容
     */
    private List<T> content;


    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        this.content = content;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }



    public int getPageTotal() {

        ///1   53%5   3     50%5   0
        pageTotal = ((recordTotal%pageSize)==0)?(recordTotal/pageSize):((recordTotal/pageSize)+1) ;
        return pageTotal;
    }

//    public void setPageTotal(int pageTotal) {
//        this.pageTotal = pageTotal;
//    }

    public int getRecordTotal() {
        return recordTotal;
    }

    public void setRecordTotal(int recordTotal) {
        this.recordTotal = recordTotal;
    }



    @Override
    public String toString() {
        return "Page{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", pageTotal=" + pageTotal +
                ", recordTotal=" + recordTotal +
                ", content=" + content +
                '}';
    }
}
